﻿using System;
using System.Collections.Generic;
using System.Linq;
using WorkFlowCore.MultipleApp;

namespace WorkFlowCore.IRepositories
{

    public class WithBaseInfoEntity<TKey> : IWithBaseInfoEntity<TKey>, IMultipleApp
    {
        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime ModifiedTime { get; set; }
        /// <summary>
        /// 更新用户id
        /// </summary>
        public string ModifiedUserId { get; set; }
        /// <summary>
        /// 创建用户id
        /// </summary>
        public string CreatedUserId { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreationTime { get; set; }
        /// <summary>
        /// 唯一标识
        /// </summary>
        public TKey Id { get; set; }
        /// <summary>
        /// 删除用户
        /// </summary>
        public string DeletedUserId { get; set; }
        /// <summary>
        /// 删除时间
        /// </summary>
        public DateTime DeletedTime { get; set; }
        /// <summary>
        /// 是否已删除（软删除）
        /// </summary>
        public bool Deleted { get; set; } = false;
        /// <summary>
        /// 应用id
        /// </summary>
        public string AppId { get; set; }

        public object[] GetKeys()
        {
            return GetType().GetProperties().Select(p => p.Name).ToArray();
        }

        public bool IsTransient()
        {
            return false;
        }

        public void Delete(string operatorId) 
        { 
            Deleted = true;
            DeletedTime = DateTime.Now;
            DeletedUserId = operatorId;
        }
    }
    public class WithBaseInfoEntity : WithBaseInfoEntity<Guid> { }
}
